package com.qeegoo.b2bautozityp.moudle.statis.view;

import com.qeegoo.b2bautozityp.R;
import com.qeegoo.b2bautozityp.databinding.ActivityStatisBinding;
import com.qeegoo.b2bautozityp.injector.component.DaggerStatisComponent;
import com.qeegoo.b2bautozityp.moudle.base.AppBar;
import com.qeegoo.b2bautozityp.moudle.base.BaseActivity;
import com.qeegoo.b2bautozityp.moudle.statis.viewmodel.StatisViewModel;
import com.qeegoo.b2bautozityp.utils.ChartUtils;

import javax.inject.Inject;

import base.lib.util.ToastUtils;

/**
 * Created by lining on 2017/9/26.
 */

public class StatisActivity extends BaseActivity<ActivityStatisBinding> {

    @Inject
    StatisViewModel mViewModel;

    @Override
    protected int attachLayoutRes() {
        return R.layout.activity_statis;
    }

    @Override
    protected void initInjector() {
        DaggerStatisComponent.builder().appComponent(getAppComponent()).build().inject(this);
    }

    @Override
    protected void initViews() {
        initToolBar(mBinding.layoutToolbar, new AppBar("统计中心", true));
        mBinding.setViewModel(mViewModel);
        ChartUtils.initChart(mBinding.chart);
        mBinding.rvOrderList.setAdapter(mViewModel.getAdapter());
        setListener();
    }

    private void setListener() {
        mViewModel.getAdapter().setOnItemClickListener((adapter, view, position) -> {
            ToastUtils.showToast(mViewModel.getAdapter().getItem(position).code);
        });
    }
    @Override
    protected void onResume() {
        super.onResume();
        mViewModel.loadHttp(mBinding.chart);
    }
}
